//
//  RdTableView.m
//  demoapp
//
//  Created by Liang Shen on 16/4/28.
//  Copyright © 2016年 Yosef Lin. All rights reserved.
//

#import "RdTableView.h"
#import "CustomEmptyView.h"
#import "UIScrollView+EmptyDataSet.h"

@interface RdTableView ()<DZNEmptyDataSetSource,DZNEmptyDataSetDelegate>

@end

@implementation RdTableView

-(id)initWithCoder:(NSCoder *)aDecoder
{
    if( self = [super initWithCoder:aDecoder] )
    {
        self.emptyDataSetSource = self;
        self.emptyDataSetDelegate = self;
        
        [self setExtraCellLineHidden:self];
    }
    return self;
}

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.emptyDataSetSource = self;
        self.emptyDataSetDelegate = self;
        
        [self setExtraCellLineHidden:self];
        
    }
    return self;
}

-(id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
{
    if (self = [super initWithFrame:frame style:style])
    {
        self.emptyDataSetSource = self;
        self.emptyDataSetDelegate = self;
        
        [self setExtraCellLineHidden:self];
    }
    return self;
}

- (void)setExtraCellLineHidden: (UITableView *)tableView{
    
    UIView *view =[ [UIView alloc]init];
    
    view.backgroundColor = [UIColor clearColor];
    
    [tableView setTableFooterView:view];
    
    [tableView setTableHeaderView:view];
    
}

#pragma mark -- 空态视图
- (UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView
{
    CustomEmptyView *view = [[CustomEmptyView alloc] init];
    
    if (_emptyText) {
        [view updateViewImage:[UIImage imageNamed:_emptyImg ] description:_emptyText];
    }
    else
    {
        [view updateViewImage:[UIImage imageNamed:@"nomsg"] description:@"暂无数据~"];
    }
    return view;
}

- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
{
    return YES;
}

- (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView
{
    if (self.showEmptyView) {
        self.separatorStyle = UITableViewCellSeparatorStyleNone;
        self.backgroundColor = [UIColor whiteColor];
    }
    else
    {   
        self.separatorStyle = UITableViewCellSeparatorStyleNone;

//        self.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        self.backgroundColor = GroupTableBackColour;
    }
    
    return self.showEmptyView;
}
@end
